package poo.esempi;

import java.util.*;


import poo.comparatori.MioComparatore;

public class UtilizzoLista {

	@SuppressWarnings({})
	public static void main(String[] args) {

		List<String> ls = new ArrayList<String>();
		ls.add("casa");
		ls.add("lupo");
		ls.add("ciao");
		Collections.sort(ls, new Comparator<String>() {
			public int compare(String s1, String s2) {
				if (s1.length() < s2.length() || s1.length() == s2.length()
						&& s1.compareTo(s2) < 0)
					return -1;
				if (s1.equals(s2))
					return 0;
				return 1;
			}
		});
		System.out.println(ls);

		Iterator<String> it = ls.iterator();

		while (it.hasNext()) {
			String x = it.next();
			System.out.println("X= " + x);
		}

		Set<Integer> s1 = new HashSet<Integer>();
		s1.add(5);
		s1.add(2);
		s1.add(3);
		s1.add(213);
		s1.add(new Integer(4));

		System.out.println(s1);

		List<Object> lo = new ArrayList<>();
		lo.add("casa");
		lo.add("zorro");
		lo.add("fuoco");

		System.out.println(lo);

		String[] as = new String[5];

		String[] as1 = lo.toArray(as);

		System.out.println(Arrays.toString(as1) + "\nas1==as " + (as1 == as));

		int[] a = { 5, 3, 12, 4, 1, 8 };

		List<Integer> li = new ArrayList<>();

		for (int i = 0; i < a.length; i++) {
			ListIterator<Integer> lit = li.listIterator();
			boolean flag = false;
			while (lit.hasNext() && !flag) {
				int y = lit.next();
				if (y >= a[i]) {
					lit.previous();
					lit.add(a[i]);
					flag = true;
				}
			}
			if (!flag)
				lit.add(a[i]);
		}

		System.out.println(li);

		LinkedList<Integer> ll = new LinkedList<>(Arrays.asList(5, 12, 19, 24));

		ll.removeFirst();
		int last = ll.getLast();

		System.out.println(ll + "\n" + last);

		LinkedList<Integer> stack = new LinkedList<>();

		stack.addLast(2);
		stack.addLast(5);
		stack.addLast(3);

		while (!stack.isEmpty()) {
			int x = stack.removeLast();
			System.out.println(x);
		}

		ArrayList<String> al = new ArrayList<>();
		al.add("zaino");
		al.add("casa");
		al.add("abaco");
		al.add("lupo");
		al.add("il");

		Collections.sort(al, new MioComparatore());

		System.out.println(al);

		HashSet<Integer> s3 = new HashSet<>();
		s3.add(2);
		s3.add(5);
		s3.add(2);
		s3.add(5);
		s3.add(3);

		System.out.println(s3);

		HashSet<Integer> s4 = new HashSet<>(Arrays.asList(5, 3, 4, 2, 5, 1, 2));

		System.out.println(s4);

		HashSet<Integer> s5 = new HashSet<>(s3);
		HashSet<Integer> s6 = new HashSet<>(s4);

		s5.removeAll(s6);

		System.out.println(s5);
	}
}
